<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.webname}</title>
    <meta name="keywords" content="{$Think.config.keyword}">
    <meta name="description" content="{$Think.config.description}">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/Huploadify/Huploadify.css"/>
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/datepicker.css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"> </script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>

<script>
var pnum = {$pnum};
{if condition="(!isset($search)) && (!isset($cate_id))"}
	var url = "/{$Request.module}/news/lst.html?page="+pnum;
{elseif condition="(isset($search)) && ($search)"/}
	var url = "/{$Request.module}/news/search.html?page="+pnum;
{elseif condition="(isset($cate_id)) && ($cate_id)"/}
    var cate_id = {$cate_id};
	var url = "/{$Request.module}/news/catelist/cate_id/"+cate_id+".html?page="+pnum;
{/if}
var updateUrl = "{:url('news/edit')}";
</script>

<body class="gray-bg">
<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>
    <div class="wrapper wrapper-content">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑文章</h5>
                    </div>
                    <div class="ibox-content">
                    <form method="post" enctype="multipart/form-data" class="form-horizontal" id="form"> 
                    
                          <div class="form-group">
                                <label class="col-sm-2 control-label">所属栏目</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="cate_id">
                                        {foreach name="cateres" item="v"}
                                        <option value="{$v.id}" {eq name="v.pid" value="0"}style="font-weight:bold;"{/eq} {if condition="$v['id'] eq $ars['cate_id']"}selected = "selected"{/if}>{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v['level'])}{gt name="v.level" value="0"}|{/gt}{$v.html}{$v.cate_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">文章标题</label>
                                <div class="col-sm-6">
                                    <input type="text" name="ar_title" value="{$ars.ar_title}" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">标识</label>
                                <div class="col-sm-6">
                                    <input type="text" name="tag" value="{$ars.tag}" placeholder="用于前端接口调用" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">作者</label>
                                <div class="col-sm-6">
                                    <input type="text" name="author" value="{$ars.author}" class="form-control">
                                </div>
                            </div>						
                            <div class="hr-line-dashed"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">出处</label>
                                <div class="col-sm-6">
                                    <input type="text" name="source" value="{$ars.source}" class="form-control">
                                </div>
                            </div>						
                            <div class="hr-line-dashed"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">发布日期</label>
                                <div class="col-sm-6">
                                    <input type="text" name="addtime" onClick="new Calendar().show(this);" readonly="readonly" value="{:date('Y-m-d',$ars['addtime'])}" class="form-control">
                                </div>
                            </div>						
                            <div class="hr-line-dashed"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-6">
                                    <input type="text" name="sort" value="{$ars.sort}" class="form-control">
                                </div>
                            </div>						
                            <div class="hr-line-dashed"></div>
                                             
                            <div class="form-group">
							<label  class="col-sm-2 control-label">文章缩略图:</label>
							<div class="col-sm-6">
                            <div style="margin-bottom:7px; margin-top:5px;">
                            <img id="image" {if condition="$ars['ar_pic']"}src="{$ars.ar_pic}"{else/}src="__PUBLIC__/admin/img/nopic.jpg"{/if} width="180" height="120" border="0" />
                            <br/><button type="button" class="btn btn-danger btn-xs del" style="display:none;">删除</button>
                            </div>
                            <div id="uploaderInput"></div>
                            <input type="hidden" name="pic_id" value="" >
                            <div class="repicm" style="display:none;">{$ars.ar_pic}</div>
                            </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">seo标题</label>
                                <div class="col-sm-6">
                                    <input type="text" name="ar_name" value="{$ars.ar_name}" class="form-control">
                                </div>
                            </div>						
                            <div class="hr-line-dashed"></div>
							
                            <div class="form-group">
                                <label class="col-sm-2 control-label">seo关键字</label>
                                <div class="col-sm-6">
                                    <input type="text" name="ar_keywords" value="{$ars.ar_keywords}" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">seo描述</label>
                                <div class="col-sm-6">
                                    <textarea id="ar_desc" name="ar_desc" class="form-control">{$ars.ar_desc}</textarea>
                                </div> 
                            </div>
                            <div class="hr-line-dashed"></div>                        
                      
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">内容简述</label>
                                <div class="col-sm-6">
                                    <textarea id="ar_jianjie" name="ar_jianjie" class="form-control">{$ars.ar_jianjie}</textarea>
                                </div> 
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否推荐</label>
                                <div class="col-sm-6" id="atype">
                                        <label class="radio-inline"><input type="radio" {if condition="$ars['is_rem'] eq 1"}checked="checked"{/if} value="1" name="is_rem">推荐</label>
                                        <label class="radio-inline"><input type="radio" {if condition="$ars['is_rem'] eq 0"}checked="checked"{/if} value="0" name="is_rem">不推荐</label>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否显示</label>
                                <div class="col-sm-6" id="atype">
                                        <label class="radio-inline"><input type="radio" {if condition="$ars['is_show'] eq 1"}checked="checked"{/if} value="1" name="is_show">显示</label>
                                        <label class="radio-inline"><input type="radio" {if condition="$ars['is_show'] eq 0"}checked="checked"{/if} value="0" name="is_show">不显示</label>
                                </div>
                            </div>
                            
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">文章正文</label>
                                <div class="col-sm-10">
                                    <textarea id="ar_content" name="ar_content">{$ars.ar_content}</textarea>
                                </div>  
                            </div>
                            <div class="hr-line-dashed"></div>
                            
                            <input type="hidden" name="id" value="{$ars.id}" />

                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit" id="doSubmit">保存内容</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/Calendar.js"></script>
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script type="text/javascript" src="__PUBLIC__/admin/Huploadify/jquery.Huploadify.js"></script>  
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>
    
    <script type="text/javascript">
		//实例化编辑器
		//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
		UE.getEditor('ar_content', {initialFrameWidth:'100%', initialFrameHeight:500, enterTag:''}); 
	</script>

	 <script>	
    	$(function(){
    		//上传图片
	        $('#uploaderInput').Huploadify({
                uploader: '{:url("Common/Upload/uploadPic")}',
		        method:'post',
		        formData:{name:'news'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
		        buttonText : '上传图像', 
		        removeTimeout: 2000,
		        fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',  
		        fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;', 
		        fileObjName: 'file', //上传附件$_FILE标识
		        fileSizeLimit : 2048,
		        //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
		        auto : true, //开启,自动上传
		        multi : false, //开启,多选文件
		        //开始上传
				onUploadStart:function(file){
					layer.load(2);
				},
		        onUploadSuccess : function(file, data, response) {
		        	//解析成json对象
		        	eval('var data='+data);
		        	if(data.status == 200){
		        		var picpath = data.data.path;
	    	        	$('#image').attr('src',picpath);
	    	        	$('.del').show();
	    	        	$('input[name=pic_id]').val(picpath);
		        	}else{
		        		layer.msg(data.mess, {icon: 2,time: 2000});
		        	}
		        },
		        //上传完成后执行的操作
		        onUploadComplete:function(file){
		        	layer.closeAll('loading');
		        },
		        //上传错误  
		        onUploadError : function(file, errorCode, errorMsg, errorString) { 
		        	layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000}); 
		        }
		    }); 
    	    
    		
    		$('.del').click(function(){

                var picval = $('.repicm').text();
                if(picval != ''){
                    $('#image').attr('src',picval);
                    $('input[name=pic_id]').val(picval);
                }else{
                    $('#image').attr('src','__PUBLIC__/admin/img/nopic.jpg');
                    $('input[name=pic_id]').val('');
                }
                $('.del').hide();
    		});
            
    	    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        	$('#form').validate({
	        	errorElement : 'span',
	        	debug: true,//只验证不提交表单
	        	//layer ajax提交表单
	            submitHandler:function(){
	               // 序列化 表单数据 后提交 ，太简洁了
	               post(updateUrl,'POST',$('#form').serialize(),1);
	               return false;
	            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法
	                
	        	rules:{
	        		ar_title:{required:true},
	        		author:{required:true},
	        		source:{required:true},
	        		cate_id:{required:true},
	        		sort:{required:true},
	        		ar_content:{required:true}
	        	},
	        		
	        	messages:{
	        		ar_title:{required:icon+'必填'},
	        		author:{required:icon+'必填'},
	        		source:{required:icon+'必填'},
	        		cate_id:{required:icon+'必选'},
	        		sort:{required:icon+'必填'},
	        		ar_content:{required:icon+'内容必填'}
	        	}
            });
      });  
    	
      function cl(){
      	 location.href = url;
      }
    </script>

</body>
</html>